#!/usr/bin/wish

# grid [ttk::button .b -text "hello" -command {button_pressed}]

# # check the value of options
# .b cget -text
# .b cget -command
# .b configure -text;				# get all info about text option
# .b configure;					# get all info

# .b configure -text "goodbye";	# change the text value


# # Event Bindings
# grid [ttk::label .l -text "Starting..."]
# bind .l <Enter> {.l configure -text "Moved mouse inside"}
# bind .l <Leave> {.l configure -text "Moved mouse outside"}
# bind .l <1> {.l configure -text "clicked left mouse button"}
# bind .l <Double-1> {.l configure -text "Double clocked"}
# bind .l <B1-Motion> {.l configure -text "Right button drag to %x %y"}
# # bind .l <B3-Motion> {.l configure -text "Right button drag to %x %y"}

# # multi bindings for a single event
# bind .l <1> {puts "you clicked left mouse button"}

# bind . <Key> {puts "You pressed %K"}



####################
## basic widgets
####################
frame .frame -width 100 -height 200

pack .frame  -padx 0 -pady 0


########## label
label .frame.label -text {hello world}
.frame.label configure -font "TkCaptionFont"
.frame.label configure -justify "left"
.frame.label configure -foreground "red" -background "yellow"

label .frame.label2
.frame.label2 configure -textvariable result;	# monitor a variable(must be global)
set result "hello, tk"

# image create photo imgobj -file "test.gif"
# .label3 configure -image imgobj
label .frame.label3 -image [image create photo imgobj -file "test.png"]

# pack .frame.label -padx 10 -pady 10
pack .frame.label
pack .frame.label2
pack .frame.label3

########## button
button .frame.button1 -text "OK" -command "test_proc"
button .frame.button2 -text "test" -command "test_settings"

proc test_proc {} {
	puts "hello"
}
proc test_settings {} {
	puts "test settings"
	set state [.frame.button1 cget -state]
	if {$state == "disabled"} {
		# .button1 configure -state !disabled
		.frame.button1 configure -state normal
	} else {
		.frame.button1 configure -state disabled
	}
}

pack .frame.button1
pack .frame.button2

# .frame.button1 invoke
# .frame.button1 configure -state disabled


########## checkbutton
checkbutton .frame.check -text "Use Metric"

pack .frame.check


########## entry
entry .frame.t1 -textvariable username
set username "hello world"

pack .frame.t1


########## combobox
set country "china"
ttk::combobox .frame.country -textvariable country -values [list China France Canada]
bind .frame.country <<ComboboxSelected>> {puts "your select : $country"}


ttk::combobox .frame.language -textvariable language -values [list C/C++ tcl python]
.frame.language current 1
.frame.language state readonly
bind .frame.language <<ComboboxSelected>> {puts "your select : $language"}

pack .frame.language




########## for debug
button .frame.b1 -text "debug1" -command "debug_1"
proc debug_1 {} {
	# puts "debug 1"
	global username
	puts $username

	puts "current value is [.frame.t1 get]"
	.frame.t1 insert 0 "your name"
	# .frame.t1 configure show "*"			   # error ??
	
}

# pack .frame.b1 -padx 10 -pady 100
pack .frame.b1

